package com.ict.web.dto;

import com.ict.common.annotation.Excel;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.SupplementaryDeclaration;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;

@Data
public class SupplementaryDeclarationAddDto {
    /** 项目名称 */
    @Excel(name = "项目名称")
    private String entryName;

    /** 项目类别:{0:建设类;1:购买服务类;2:运维类;3:其他} */
    @Excel(name = "项目类别:{0:建设类;1:购买服务类;2:运维类;3:其他}")
    private String projectCategory;

    /** 项目投资估算（万元） */
    @Excel(name = "项目投资估算", readConverterExp = "万=元")
    private BigDecimal projectInvestmentEstimation;

    /** 资金来源 */
    @Excel(name = "资金来源")
    private String sourceOfFunds;

    /** 增补凭证 */
    @Excel(name = "增补凭证")
    private YzqFileDTO supplementaryVoucher;

    /** 项目建议书（新建项目） */
    @Excel(name = "项目建议书", readConverterExp = "新=建项目")
    private YzqFileDTO projectProposal;

    /** 项目建设理由 */
    @Excel(name = "项目建设理由")
    private String reasonsForProjectConstruction;

    /** 项目内容简介 */
    @Excel(name = "项目内容简介")
    private String projectContentIntroduction;

    /** 预期效果描述 */
    @Excel(name = "预期效果描述")
    private String expectedEffectDescription;

    /** 前期工作完成情况 */
    @Excel(name = "前期工作完成情况")
    private String preliminaryWorkCompletion;

    /** 项目负责人 */
    @Excel(name = "项目负责人")
    private String projectLeader;

    /** 负责人电话 */
    @Excel(name = "负责人电话")
    private String telephoneNumber;

    /** 项目联系人 */
    @Excel(name = "项目联系人")
    private String projectContact;

    /** 联系人电话 */
    @Excel(name = "联系人电话")
    private String contactTelephone;

    /** 暂存标识（0：正常1：暂存） */
    @ApiModelProperty(value = "暂存标识（0：正常1：暂存）")
    @Excel(name = "暂存标识", readConverterExp = "0=：正常1：暂存")
    private String temporaryFlag;

    /** 建设单位 */
    @ApiModelProperty(value = "建设单位")
    private String constructionUnit;

    /** 所属部门 */
    @ApiModelProperty(value = "所属部门")
    private String department;
    /**
     * 将 AnnualProjectPlanAddDto 转化为 AnnualProjectPlan
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static SupplementaryDeclaration of(SupplementaryDeclarationAddDto dto){
        SupplementaryDeclaration bean = new SupplementaryDeclaration();
        BeanUtils.copyProperties(dto,bean);

        //设置ID
        bean.setSupplementaryId(IdUtils.snowId());
        //设置创建时间
        bean.setCreateTime(LocalDateTime.now());
        //设置创建时间
        bean.setUpdateTime(LocalDateTime.now());
        //设置物理删除标记
        bean.setDelFlag("0");
//        //设置暂存标记 (0：正常 1：暂存)
//        bean.setTemporaryFlag("0");

        return bean;
    }

    /**
     * 将 SupplementaryDeclarationAddDto中需传文件对象 转化为 file
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static ArrayList<YzqFile> toFile(SupplementaryDeclaration supplementaryDeclaration, SupplementaryDeclarationAddDto dto) {
        ArrayList<YzqFile> fileList = new ArrayList<>();
        if (dto.getSupplementaryVoucher() != null) {
            YzqFileDTO Sv = dto.getSupplementaryVoucher();
            YzqFile fileSv = new YzqFile();
            fileSv.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(Sv, fileSv);
            fileList.add(fileSv);
            supplementaryDeclaration.setSupplementaryVoucher(fileSv.getId());
        }

        if (dto.getProjectProposal() != null) {
            YzqFileDTO Pp = dto.getProjectProposal();
            YzqFile filePp = new YzqFile();
            filePp.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(Pp, filePp);
            fileList.add(filePp);
            supplementaryDeclaration.setProjectProposal(filePp.getId());
        }
        return fileList;
    }
}
